package com.yun.blog.controller;


import com.yun.blog.bean.Comment;
import com.yun.blog.bean.Result;
import com.yun.blog.service.CommentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 博客评论接口
 * title        : CommentController
 * projectName  : dantouBlog-back
 * description  : 博客评论接口
 * author       : simple
 * date         : 2023-05-04 21:38
 */

@Slf4j
@RestController
@RequestMapping("/comment")
@Api(tags = "评论接口")
public class CommentController {

    @Resource
    private CommentService commentService;

    /**
     *
     * @author yun
     * @date 2023/5/5 下午10:51
     * @param comment 评论内容
     * @return Result
     */
    @PostMapping("/addComment")
    @ApiOperation("添加评论")
    public Result addComment(@RequestBody Comment comment) {
        commentService.save(comment);
        return Result.success("添加成功");
    }

    /**
     * 通过博客id获取评论
     * @author yun
     * @date 2023/5/5 下午11:06
     * @param blogId 博客id
     * @return Result
     */
    @GetMapping("/getCommentsByBlogId")
    @ApiOperation("通过博客id获取评论")
    public Result getCommentsByBlogId(Integer blogId){
        List<Comment> comments = commentService.getCommentsByBlogId(blogId);
        return Result.success().add("comments",comments);
    }



}
